/**
*  struct ListNode {
*        int val;
*        struct ListNode *next;
*        ListNode(int x) :
*              val(x), next(NULL) {
*        }
*  };
*/
class Solution
{
public:
    vector<int> printListFromTailToHead(ListNode* head)
    {
        stack<int> ret;
        while (head != nullptr)
        {
            ret.push(head->val);
            head = head->next;
        }

        vector<int> res;
        while (!ret.empty())
        {
            res.push_back(ret.top());
            ret.pop();
        }
        return res;
    }
};
